<template>
    <view class="body-view">
        <!--导航和状态栏-->
        <view class="state-navigation psr" style="z-index:100;">
            <view class="slim_header_navigation d-flex a-center j-center">
                <view class="left_box" @tap="goBack">
                    <image src="/static/center/back.png" class="back"></image>
                </view>
                <view class="title"></view>
                <view class="right_box">
                    <!-- <image src="/static/center/dian.png" class="dian"></image> -->
                </view>
            </view>
        </view>
        <!-- 顶部位置占位 -->
        <!-- <view style="height: calc(10rpx + var(--status-bar-height))"></view> -->
        <scroll-view scroll-y="true" class="scroll-y">
            <view class="top-title d-flex">
                <view class="title-content">
                    <view class="content-title">欢迎来到轻盈</view>
                    <view class="content-describe"
                        >在开始瘦身之前，我们需要知道您的身体数据，轻盈将严格保护您的个人信息安全！</view
                    >
                </view>
                <image
                    class="title-image"
                    src="../../static/juzhong.png"
                ></image>
            </view>
            <view class="middle-form">
                <view class="form-content">
                    <uni-forms
                        ref="form"
                        err-show-type="toast"
                        :rules="rules"
                        :modelValue="formData"
                        :label-width="0"
                    >
                        <uni-forms-item name="sex">
                            <view class="sex_box d-flex">
                                <view class="dot d-flex a-center j-center">
                                    性别
                                </view>
                                <view class="row-cell d-flex j-center">
                                    <view class="cell-content">
                                        <image
                                            v-if="formData.sex == 1"
                                            class="cell-img"
                                            src="@/static/userinfo/nan-z.png"
                                        ></image>
                                        <image
                                            v-else
                                            class="cell-img"
                                            src="@/static/userinfo/nanw.png"
                                            @tap="handleSexChange(1)"
                                        ></image>
                                        <view class="d-flex j-center">
                                            <view class="cell-text d-flex">
                                                <view
                                                    class="text-text"
                                                    :class="{
                                                        sel: formData.sex == 1,
                                                    }"
                                                    >男</view
                                                >
                                            </view>
                                        </view>
                                    </view>
                                </view>
                                <view class="row-cell d-flex j-center">
                                    <view class="cell-content">
                                        <image
                                            v-if="formData.sex == 2"
                                            class="cell-img"
                                            src="@/static/userinfo/nv-z.png"
                                        ></image>
                                        <image
                                            v-else
                                            class="cell-img"
                                            src="@/static/userinfo/nvw.png"
                                            @tap="handleSexChange(2)"
                                        ></image>
                                        <view class="d-flex j-center">
                                            <view class="cell-text d-flex">
                                                <view
                                                    class="text-text"
                                                    :class="{
                                                        sel: formData.sex == 2,
                                                    }"
                                                    >女</view
                                                >
                                            </view>
                                        </view>
                                    </view>
                                </view>
                            </view>

                            <!-- <view class="d-flex j-between">
                                <view class="box weight">
                                    <view class="dot d-flex a-center j-center">
                                        初始体重
                                    </view>
                                </view>
                                <view class="box targetWeight">
                                    <view class="dot d-flex a-center j-center">
                                        目标体重
                                    </view>
                                </view>
                            </view> -->

                            <!-- <view class="form-row d-flex">
                                <view class="row-title d-flex a-center"
                                    >性别</view
                                >
                                <view
                                    class="row-input d-flex a-center"
                                    @tap="showSexPopup"
                                >
                                    <view
                                        v-if="formData.sex == null"
                                        class="input-placeholder"
                                        >请选择性别</view
                                    >
                                    <view
                                        v-if="formData.sex == 1"
                                        class="input-show d-flex a-center"
                                    >
                                        <image
                                            class="show-image"
                                            src="/static/userinfo/nan-icon.png"
                                        ></image>
                                        <view class="show-text">男</view>
                                    </view>
                                    <view
                                        v-if="formData.sex == 2"
                                        class="input-show d-flex a-center"
                                    >
                                        <image
                                            class="show-image"
                                            src="/static/userinfo/nv-icon.png"
                                        ></image>
                                        <text class="show-text">女</text>
                                    </view>
                                    <input
                                        v-show="false"
                                        :disabled="true"
                                        :adjust-position="false"
                                        placeholder-class="placeholder"
                                        type="text"
                                        v-model="formData.sex"
                                        placeholder="请选择性别"
                                    />
                                    <i
                                        class="icon row-navigation icon-more-2"
                                    ></i>
                                </view>
                            </view> -->
                        </uni-forms-item>

                        <view class="d-flex j-between">
                            <uni-forms-item name="birthday">
                                <view
                                    class="box d-flex d-c a-center j-center age"
                                    @tap="showBirthdayPopup"
                                >
                                    <view class="dot d-flex a-center j-center">
                                        年龄
                                    </view>
                                    <view class="main" v-if="formData.birthday">
                                        <text>{{ age }}</text>
                                        <text class="unit">岁</text>
                                    </view>

                                    <view class="desp" v-if="formData.birthday">
                                        {{ formData.birthday }}
                                    </view>

                                    <view class="desp" v-if="!formData.birthday"
                                        >请填入年龄</view
                                    >
                                </view>
                            </uni-forms-item>
                            <uni-forms-item name="stature">
                                <view
                                    class="box d-flex a-center j-center height"
                                    @tap="showHeightPopup"
                                >
                                    <view class="dot d-flex a-center j-center">
                                        身高
                                    </view>
                                    <view class="main" v-if="formData.stature">
                                        <text>{{ formData.stature }}</text>
                                        <text class="unit">cm</text>
                                    </view>
                                    <view class="desp" v-if="!formData.stature"
                                        >请填入身高</view
                                    >
                                </view>
                            </uni-forms-item>
                        </view>


                        <view class="d-flex j-between">
                            <uni-forms-item name="initWeight">
                                <view
                                    class="box d-flex a-center j-center weight"
                                    @tap="showInitWeight"
                                >
                                    <view class="dot d-flex a-center j-center">
                                        初始体重
                                    </view>

                                    <view
                                        class="main"
                                        v-if="formData.initWeight"
                                    >
                                        <text>{{
                                            Number(formData.initWeight)
                                        }}</text>
                                        <text class="unit">kg</text>
                                    </view>

                                    <view
                                        class="desp"
                                        v-if="!formData.initWeight"
                                        >请填入初始体重</view
                                    >
                                </view>
                            </uni-forms-item>
                            <uni-forms-item name="aimWeight">
                                <view
                                    class="box d-flex a-center j-center targetWeight"
                                    @tap="showAimWeight"
                                >
                                    <view class="dot d-flex a-center j-center">
                                        目标体重
                                    </view>

                                    <view
                                        class="main"
                                        v-if="formData.aimWeight"
                                    >
                                        <text>{{
                                            Number(formData.aimWeight)
                                        }}</text>
                                        <text class="unit">kg</text>
                                    </view>

                                    <view
                                        class="desp"
                                        v-if="!formData.aimWeight"
                                        >请填入目标体重</view
                                    >
                                </view>
                            </uni-forms-item>
                        </view>

                        <uni-forms-item name="heatIsPoor">
                            <view class="heat_box">
                                <view class="dot d-flex a-center j-center"
                                    >每日热量差</view
                                >
                                <view
                                    v-if="
                                        formData.heatIsPoor != null &&
                                        formData.heatIsPoor >= 201 &&
                                        formData.heatIsPoor <= 500
                                    "
                                    class="suggest"
                                    >推荐</view
                                >

                                <view class="main d-flex a-center j-center" @tap="showCaloriePopup">
                                    <view
                                        class="num d-flex j-center"
                                    >
                                        <text v-if="formData.heatIsPoor" class="text">{{ formData.heatIsPoor }}</text>
                                        <text v-if="!formData.heatIsPoor" class="desp1">请填写热量差</text>
                                    </view>
                                    <view
                                        class="unit"
                                        >千卡</view
                                    >
                                </view>

                                <view class="content-count d-flex">
                                    <view class="count-describe d-flex d-c a-center">
                                        <view class="describe-title"
                                            >约等于</view
                                        >
                                        <view class="describe-symbol">≈</view>
                                    </view>
                                    <view class="count-contrast d-flex">
                                        <view class="contrast-food">
                                            <image
                                                class="food-image"
                                                src="../../static/image/egg.png"
                                            ></image>
                                            <view class="food-describe"
                                                >{{
                                                    equivalent.egg
                                                }}个鸡蛋</view
                                            >
                                        </view>
                                        <view class="contrast-or d-flex a-center j-center">
                                            <view
                                                class="or-text d-flex a-center j-center"
                                                >或</view
                                            >
                                        </view>
                                        <view class="contrast-food">
                                            <image
                                                class="food-image"
                                                src="../../static/image/rice.png"
                                            ></image>
                                            <view class="food-describe"
                                                >{{
                                                    equivalent.rice
                                                }}克米饭</view
                                            >
                                        </view>
                                        <view class="contrast-or d-flex a-center j-center">
                                            <view
                                                class="or-text d-flex a-center j-center"
                                                >或</view
                                            >
                                        </view>
                                        <view class="contrast-food">
                                            <image
                                                class="food-image"
                                                src="../../static/image/drumstick.png"
                                            ></image>
                                            <view class="food-describe"
                                                >{{
                                                    equivalent.drumstick
                                                }}个炸鸡腿</view
                                            >
                                        </view>
                                    </view>
                                </view>
                                <view class="content-describe">
                                    <view>热量差=每日消耗热量-每日摄入热量</view>
                                    <view>{{ equivalent.describe }}</view>
                                </view>
                            </view>


                        </uni-forms-item>

                        <!-- <uni-forms-item name="birthday">
                            <view class="form-row d-flex">
                                <view class="row-title d-flex a-center"
                                    >出生日期</view
                                >
                                <view
                                    class="row-input d-flex a-center"
                                    @tap="showBirthdayPopup"
                                >
                                    <view
                                        v-if="formData.birthday == null"
                                        class="input-placeholder"
                                        >请选择出生日期</view
                                    >
                                    <view
                                        v-if="formData.birthday != null"
                                        class="input-show d-flex a-center"
                                    >
                                        <text class="show-text">{{
                                            formData.birthday
                                        }}</text>
                                    </view>
                                    <input
                                        v-show="false"
                                        :disabled="true"
                                        :adjust-position="false"
                                        class="input-input"
                                        placeholder-class="placeholder"
                                        type="text"
                                        v-model="formData.birthday"
                                    />
                                    <i
                                        class="icon row-navigation icon-more-2"
                                    ></i>
                                </view>
                            </view>
                        </uni-forms-item> -->

                        <!-- <uni-forms-item name="stature">
                            <view class="form-row d-flex">
                                <view class="row-title d-flex a-center"
                                    >身高</view
                                >
                                <view
                                    class="row-input d-flex a-center"
                                    @tap="showHeightPopup"
                                >
                                    <view
                                        v-if="formData.stature == null"
                                        class="input-placeholder"
                                        >请选择身高</view
                                    >
                                    <view
                                        v-if="formData.stature != null"
                                        class="input-show d-flex a-center"
                                    >
                                        <text class="show-text">{{
                                            selectedHeight
                                        }}</text>
                                    </view>
                                    <input
                                        v-show="false"
                                        :disabled="true"
                                        :adjust-position="false"
                                        class="input-input"
                                        placeholder-class="placeholder"
                                        type="text"
                                        v-model="formData.stature"
                                    />
                                    <i
                                        class="icon row-navigation icon-more-2"
                                    ></i>
                                </view>
                            </view>
                        </uni-forms-item> -->

                        <!-- <uni-forms-item name="initWeight">
                            <view class="form-row d-flex">
                                <view class="row-title d-flex a-center"
                                    >初始体重</view
                                >
                                <view
                                    class="row-input d-flex a-center"
                                    @tap="showInitWeight"
                                >
                                    <view
                                        v-if="formData.initWeight == null"
                                        class="input-placeholder"
                                        >请选择初始体重</view
                                    >
                                    <view
                                        v-if="formData.initWeight != null"
                                        class="input-show d-flex a-center"
                                    >
                                        <text class="show-text">{{
                                            selectedInitWeight
                                        }}</text>
                                    </view>
                                    <input
                                        v-show="false"
                                        :disabled="true"
                                        :adjust-position="false"
                                        class="input-input"
                                        placeholder-class="placeholder"
                                        type="text"
                                        v-model="formData.initWeight"
                                    />
                                    <i
                                        class="icon row-navigation icon-more-2"
                                    ></i>
                                </view>
                            </view>
                        </uni-forms-item> -->

                        <!-- <uni-forms-item name="aimWeight">
                            <view class="form-row d-flex">
                                <view class="row-title d-flex a-center"
                                    >目标体重</view
                                >
                                <view
                                    class="row-input d-flex a-center"
                                    @tap="showAimWeight"
                                >
                                    <view
                                        v-if="formData.aimWeight == null"
                                        class="input-placeholder"
                                        >请选择目标体重</view
                                    >
                                    <view
                                        v-if="formData.aimWeight != null"
                                        class="input-show d-flex a-center"
                                    >
                                        <text class="show-text">{{
                                            selectedAimWeight
                                        }}</text>
                                    </view>
                                    <input
                                        v-show="false"
                                        :disabled="true"
                                        :adjust-position="false"
                                        class="input-input"
                                        placeholder-class="placeholder"
                                        type="text"
                                        v-model="formData.aimWeight"
                                    />
                                    <i
                                        class="icon row-navigation icon-more-2"
                                    ></i>
                                </view>
                            </view>
                        </uni-forms-item> -->

                        <!-- <uni-forms-item name="heatIsPoor">
                            <view class="form-row d-flex">
                                <view class="row-title d-flex a-center"
                                    >每日热量差</view
                                >
                                <view
                                    class="row-input d-flex a-center"
                                    @tap="showCaloriePopup"
                                >
                                    <view
                                        v-if="formData.heatIsPoor == null"
                                        class="input-placeholder"
                                        >请选择热量差</view
                                    >
                                    <view
                                        v-if="formData.heatIsPoor != null"
                                        class="input-show d-flex a-center"
                                    >
                                        <text class="show-text">{{
                                            selectedCalorie
                                        }}</text>
                                    </view>
                                    <input
                                        v-show="false"
                                        :disabled="true"
                                        :adjust-position="false"
                                        class="input-input"
                                        placeholder-class="placeholder"
                                        type="text"
                                        v-model="formData.heatIsPoor"
                                    />
                                    <view
                                        v-if="
                                            formData.heatIsPoor != null &&
                                            formData.heatIsPoor >= 201 &&
                                            formData.heatIsPoor <= 500
                                        "
                                        class="input-suggest d-flex"
                                        >推荐</view
                                    >
                                    <i
                                        v-else
                                        class="icon row-navigation icon-more-2"
                                    ></i>
                                </view>
                            </view>
                        </uni-forms-item> -->
                    </uni-forms>
                    <!-- <view class="content-count d-flex">
                        <view class="count-describe">
                            <view class="describe-title">约等于</view>
                            <view class="describe-symbol">≈</view>
                        </view>
                        <view class="count-contrast d-flex">
                            <view class="contrast-food">
                                <image
                                    class="food-image"
                                    src="../../static/image/egg.png"
                                ></image>
                                <view class="food-describe"
                                    >{{ equivalent.egg }}个鸡蛋</view
                                >
                            </view>
                            <view class="contrast-or">
                                <view class="or-text d-flex a-center j-center"
                                    >或</view
                                >
                            </view>
                            <view class="contrast-food">
                                <image
                                    class="food-image"
                                    src="../../static/image/rice.png"
                                ></image>
                                <view class="food-describe"
                                    >{{ equivalent.rice }}克米饭</view
                                >
                            </view>
                            <view class="contrast-or">
                                <view class="or-text d-flex a-center j-center"
                                    >或</view
                                >
                            </view>
                            <view class="contrast-food">
                                <image
                                    class="food-image"
                                    src="../../static/image/drumstick.png"
                                ></image>
                                <view class="food-describe"
                                    >{{ equivalent.drumstick }}个炸鸡腿</view
                                >
                            </view>
                        </view>
                    </view>
                    <view class="content-describe">
                        <view>热量差=每日消耗热量-每日摄入热量</view>
                        <view>热量差=每日消耗热量-每日摄入热量</view>
                        <view>热量差=每日消耗热量-每日摄入热量</view>
                        <view>{{ equivalent.describe }}</view>
                    </view> -->
                </view>
            </view>
            <!--底部站位-->
            <view class="bottom-v"></view>
        </scroll-view>


        <view class="btn_bottom_box">
            <view class="btn_main_r" @tap="confirm">
                <text class="text">
                    确定
                </text>
            </view>
            <view class="bottom_seat"></view>
        </view>


        <!-- <view class="bottom-button d-flex j-center">
            <tm-button
                round="5"
                _style="margin: 0 auto;font-weight: 600;"
                :width="650"
                :shadow="-1"
                :linear-color="['#64F1C5', '#29DBA3']"
                linear="left"
                :fontSize="32"
                fontColor="#FFFFFF"
                @tap="confirm"
                label="确定"
            ></tm-button>
        </view> -->
        <!--性别选择-->
        <gender ref="sexPopup" @onGetSex="onGetSex" />
        <!--出生日期选择-->
        <datepicker
            ref="birthdayPopup"
            @onGetDate="onGetDate"
            @onGetAge="onGetAge"
        ></datepicker>
        <!--身高选择-->
        <height ref="heightPopup" @onGetHeight="onGetHeight" />
        <!--初始体重选择-->
        <weight ref="initWeightPopup" @onGetWeight="onGetInitWeight" />
        <!--目标体重选择-->
        <weight ref="aimWeightPopup" @onGetWeight="onGetAimWeight" />
        <!--热量差选择-->
        <calorie ref="caloriePopup" @onGetCalorie="onGetCalorie" />
        <!-- 性别确认按钮 -->
        <uni-popup ref="sexConfirmPopup" type="center">
            <view class="sex-confirm">
                <view class="d-flex j-center">
                    <view class="sex-icon">
                        <image
                            v-if="formData.sex == 1"
                            class="icon-image"
                            src="@/static/userinfo/nan-z.png"
                        ></image>
                        <image
                            v-if="formData.sex == 2"
                            class="icon-image"
                            src="@/static/userinfo/nv-z.png"
                        ></image>
                        <view
                            v-if="formData.sex == 1"
                            class="icon-background male d-flex a-center j-center"
                        >
                            <i class="gender-icon icon icon-nansheng"></i>
                        </view>
                        <view
                            v-if="formData.sex == 2"
                            class="icon-background female d-flex a-center j-center"
                        >
                            <i class="gender-icon icon icon-nvsheng"></i>
                        </view>
                    </view>
                </view>
                <view v-if="formData.sex == 1" class="confirm-sex d-flex j-center">男</view>
				<view v-if="formData.sex == 2" class="confirm-sex d-flex j-center">女</view>
                <view class="confirm-title d-flex j-center"
                    >请确认性别选择</view
                >
                <view class="confirm-describe d-flex j-center"
                    >性别会影响身体数据计算<br />选择后将不可更改</view
                >
                <view class="confirm-confirm d-flex j-center">
                    <tm-button
                        class="confirm-button"
                        :width="594"
                        :shadow="-1"
                        :linear-color="['#64F1C5', '#29DBA3']"
                        linear="left"
                        :fontSize="32"
                        fontColor="#FFFFFF"
                        @tap="submit"
                        label="确认"
                    ></tm-button>
                </view>
                <view class="confirm-cancel d-flex j-center">
                    <view class="cancel-button" @tap="sexConfirmPopup.close()"
                        >重新选择</view
                    >
                </view>
            </view>
        </uni-popup>
    </view>
</template>

<script setup lang="tsx" name="bodyInfo">
import { ref } from "vue";
import gender from "./components/gender.vue";
import datepicker from "./components/datepicker.vue";
import height from "./components/height.vue";
import weight from "./components/weight.vue";
import calorie from "./components/calorie.vue";
import { addHealthRecord } from "@/api/api";
import { userData as userDataStore } from "@/store/userData";
import { setBodyData } from "@/hooks/bodyData";
import moment from "moment";
import { onLoad } from "@dcloudio/uni-app";

const goBack = () => {
    uni.navigateBack();
};
const formData: any = ref({
	heatIsPoor:500
});
onLoad(()=> {
	heatConvert();
})
//选择性别相关
const sexPopup = ref();
const showSexPopup = () => {
    sexPopup.value.showPopup(1);
};

const age = ref(null);

const onGetSex = (props: any) => {
    console.log(props);
    formData.value.sex = props;
};

const handleSexChange = (number: number) => {
    formData.value.sex = number;
};

//出生日期选择相关
const birthdayPopup = ref();
const showBirthdayPopup = () => {
    //传默认日期
    birthdayPopup.value.showPopup(formData.value.birthday);
};
const onGetDate = (e: any) => {
    formData.value.birthday = e;
};

const onGetAge = (e: any) => {
    console.log("onGetAge");
    console.log(e);
    age.value = e;
};
//身高选择
const heightPopup = ref();
const showHeightPopup = () => {
    heightPopup.value.showPopup(formData.value.stature);
};
const selectedHeight: any = ref({ id: 0 });
const onGetHeight = (e: any) => {
    selectedHeight.value = e + "cm";
    formData.value.stature = e;
};
//初始体重选择
const initWeightPopup = ref();
const showInitWeight = () => {
    let params = {
        title: "初始体重",
        initialVlue: formData.value.initWeight,
    };
    initWeightPopup.value.showPopup(params);
};
const selectedInitWeight: any = ref();
const onGetInitWeight = (e: any) => {
    selectedInitWeight.value = e + "kg";
    formData.value.initWeight = e;

    loseWeight();
};
//目标体重选择
const aimWeightPopup = ref();
const showAimWeight = () => {
    let params = {
        title: "目标体重",
        initialVlue: formData.value.aimWeight,
    };
    aimWeightPopup.value.showPopup(params);
};
const selectedAimWeight: any = ref();
const onGetAimWeight = (e: any) => {
    selectedAimWeight.value = e + "kg";
    formData.value.aimWeight = e;

    loseWeight();
};
//热量差选择
const caloriePopup = ref();
const showCaloriePopup = () => {
    caloriePopup.value.showPopup(formData.value.heatIsPoor);
};
const selectedCalorie: any = ref();
const equivalent: any = ref({
    egg: 0,
    rice: 0,
    drumstick: 0,
    describe: "",
});
const onGetCalorie = (e: any) => {
    let heatIsPoor = Number(e);
    selectedCalorie.value = e + "千卡";
    formData.value.heatIsPoor = Number(e);
    //计算当量
	/*
    let egg = 73; //60g的鸡蛋每个含热量
    let rice = 116; //100g的米饭每个含热量
    let drumstick = 292; //120g的炸鸡腿每个含热量;
    equivalent.value.egg = calculateEquivalent(heatIsPoor, egg);
    equivalent.value.rice = Math.round((heatIsPoor / rice) * 10) * 10; //calculateEquivalent(heatIsPoor,rice);
    equivalent.value.drumstick = calculateEquivalent(heatIsPoor, drumstick);
	*/
	heatConvert();
    loseWeight();
};
const heatConvert = () => {
	let egg = 73; //60g的鸡蛋每个含热量
	let rice = 116; //100g的米饭每个含热量
	let drumstick = 292; //120g的炸鸡腿每个含热量;
	equivalent.value.egg = calculateEquivalent(formData.value.heatIsPoor, egg);
	equivalent.value.rice = Math.round((formData.value.heatIsPoor / rice) * 10) * 10; //calculateEquivalent(heatIsPoor,rice);
	equivalent.value.drumstick = calculateEquivalent(formData.value.heatIsPoor, drumstick);
}
//计算当量
const calculateEquivalent = (heatIsPoor: number, equivalent: number) => {
    let num = parseFloat(
        (Math.round((heatIsPoor / equivalent) * 100) / 100).toFixed(2)
    );
    if (num % 1 == 0) {
        return num;
    } else {
        let str = num.toString().split(".");
        let result = Number(str[0]);

        switch (Math.floor(Number("0." + str[1]) / 0.25)) {
            case 1:
                result += 0.5;
                break;
            case 2:
                result += 0.5;
                break;
            case 3:
                result += 1;
                break;
        }
        //console.log(Math.floor(Number("0."+str[1]) / 0.25),result)
        return result;
        //console.log(Number("0."+str[1]),(Math.floor(Number("0."+str[1]) / 0.25)))
        //return str[0] + "." + (Number(str[1]) % 25)
        //console.log(0.5%0.25)
    }
    //每0.25进0.5
    //return ((heatIsPoor / equivalent) * 100).toFixed(3);
};
//计算减重信息
const loseWeight = () => {
    if (
        formData.value.initWeight == null ||
        formData.value.aimWeight == null ||
        formData.value.heatIsPoor == null
    )
        return;
    let initWeight = parseFloat(formData.value.initWeight);
    let aimWeight = parseFloat(formData.value.aimWeight);
    let heatIsPoor = Number(formData.value.heatIsPoor);
    //如果初始重量小于等于目标重量则返回不做计算
    equivalent.value.describe = "";
    if (initWeight <= aimWeight) return;
    let ratio = 7.7; //热量比率

    //每周减重千克数
    let weekly = parseFloat((heatIsPoor / ratio / 1000 * 7).toFixed(2));
    //预计完成天数
    let day = Math.ceil(((initWeight - aimWeight) /  weekly ) * 7);

    if (heatIsPoor >= 100 && heatIsPoor <= 200) {
        equivalent.value.describe =
            "按此热量差，非常容易实现，减肥效果可能不明显，可保持目前体重。";
    }
    if (heatIsPoor >= 201 && heatIsPoor <= 350) {
        equivalent.value.describe =
            "按此热量差，容易实现，每周可减重" +
            weekly +
            "千克，预计" +
            day +
            "天可达到目标体重。";
    }
    if (heatIsPoor >= 351 && heatIsPoor <= 500) {
        equivalent.value.describe =
            "按此热量差，有一定挑战，每周可减重" +
            weekly +
            "千克，预计" +
            day +
            "天可达到目标体重。";
    }
    if (heatIsPoor >= 501 && heatIsPoor <= 700) {
        equivalent.value.describe =
            "按此热量差，有一定挑战，可能影响身体健康，每周可减重" +
            weekly +
            "千克。";
    }
    if (heatIsPoor >= 701 && heatIsPoor <= 1000) {
        equivalent.value.describe =
            "按此热量差，难度较大且影响身体健康，每周可减重" +
            weekly +
            "千克。";
    }
    if (heatIsPoor >= 1001 && heatIsPoor <= 1500) {
        equivalent.value.describe =
            "按此热量差，严重影响身体健康，不建议按此方案执行。";
    }
};
const rules: any = ref({
    sex: {
        rules: [
            {
                required: true,
                errorMessage: "请选择性别",
            },
        ],
    },
    birthday: {
        rules: [
            {
                required: true,
                errorMessage: "请填入年龄",
            },
        ],
    },
    stature: {
        rules: [
            {
                required: true,
                errorMessage: "请填入身高",
            },
        ],
    },
    initWeight: {
        rules: [
            {
                required: true,
                errorMessage: "请填入初始体重",
            },
        ],
    },
    aimWeight: {
        rules: [
            {
                required: true,
                errorMessage: "请填入目标体重",
            },
        ],
    },
    heatIsPoor: {
        rules: [
            {
                required: true,
                errorMessage: "请填写热量差",
            },
        ],
    },
});
const form = ref();
const userData: any = userDataStore();
const sexConfirmPopup = ref();
const confirm = () => {
    form.value
        .validate()
        .then((res: any) => {


            if (parseFloat(res.initWeight) <= parseFloat(res.aimWeight)) {
                uni.showToast({
                    title: "目标体重应小于初始体重",
                    icon: "none",
                    duration: 2000,
                });
                return;
            }
            sexConfirmPopup.value.open();
        })
        .catch((err: any) => {
            console.log("表单错误信息：", err);
        });
};
const submit = () => {
    form.value
        .validate()
        .then((res: any) => {
            res.userId = userData.id;
            res.birthday = moment(res.birthday, "YYYY年MM月DD日").format(
                "YYYY-MM-DD"
            );
			console.log(res)
			//return;
            addHealthRecord(res).then((data: any) => {
                if (data.success) {
                    uni.showToast({
                        title: data.message,
                        icon: "success",
                        duration: 2000,
                    });

                    setBodyData({inited:true});
                    setTimeout(function () {

                        uni.navigateBack({ delta: 1 });
                    }, 500);
                } else {
                    uni.showToast({
                        title: data.message,
                        icon: "error",
                        duration: 2000,
                    });
                }
            });
        })
        .catch((err: any) => {
            console.log("表单错误信息：", err);
        });
};
//@tap="goUrl('/programme/programme')"
</script>

<style lang="scss" scoped>
@import "./bodyInfo.scss";

.body-view {
    .sex_box {
        width: 670rpx;
        height: 170rpx;
        background: #f7f9f8;
        border-radius: 10rpx;
        .dot {
            position: absolute;
            top: 0;
            left: 0;
            width: 70rpx;
            height: 40rpx;
            background: #fafbd8;
            border-radius: 10rpx 0px 10rpx 0px;
            font-size: 24rpx;
            color: #888b27;
        }
        .row-cell {
            width: 50%;
            .cell-content {
                width: 100rpx;
                margin-top: 10rpx;
                .cell-img {
                    width: 100rpx;
                    height: 100rpx;
                }
                .cell-text {
                    .text-icon {
                        width: 36rpx;
                        height: 36rpx;
                    }
                    .text-text {
                        font-size: 32rpx;
                        font-family: PingFangSC-Regular, PingFang SC;
                        font-weight: 400;
                        color: #ccc;
                        &.sel {
                            color: #333;
                        }
                    }
                }
            }
        }
    }
    .heat_box {
        position: relative;
        width: 670rpx;
        height: 480rpx;
        background: #f7f9f8;
        border-radius: 10rpx;
        margin-top: 20rpx;
        overflow: hidden;
        .dot {
            position: absolute;
            top: 0;
            left: 0;
            width: 150rpx;
            height: 40rpx;
            background: #d3f9ed;
            border-radius: 10rpx 0px 10rpx 0px;
            font-size: 24rpx;
            color: #1dc691;
        }
        .suggest {
            position: absolute;
            top: 20rpx;
            right: 20rpx;
            font-size: 28rpx;
            color: #1dc691;
        }

        .main {
            width:100%;
            height: 60rpx;
            margin-top: 56rpx;
            .num {
                width: 140rpx;
                height: 60rpx;
                border-bottom: 2rpx solid #59edbf;
                font-family: 'din',DINAlternate-Bold, DINAlternate;
                font-weight: bold;
                color: #333333;
                font-size: 42rpx;
                text-decoration: nowrap;
                .desp1{
                    font-size:22rpx;
                    color: #999;
                    position:relative;
                    top:10rpx;
                }
                .text{
                    position:relative;
                    top:-5rpx;
                }
            }
            .unit {
                position: relative;
                top: -5rpx;
                margin-left: 10rpx;
            }

            .desp {
                font-size: 24rpx;
                color: #999;
            }
        }

        .content-count{
				padding: 27rpx 25rpx 23rpx 3rpx;
				border-bottom: 1rpx solid #F5F5F5;  
				.count-describe{
                    width:195rpx;
                    display: flex;
                    align-items: center;
                    justify-content: center;
					.describe-title{
						padding-top: 14rpx;
						font-size: 28rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
						color: #666666;
					}
					.describe-symbol{
						margin-top: -25rpx;
						font-size: 60rpx;
						font-family: PingFangSC-Regular, PingFang SC;
						font-weight: 400;
						color: #1DC691;
						text-align: center;
					}
				}
				.count-contrast{
					.contrast-food{
                        display: flex;
                        align-items: center;
                        justify-content: center;
                        flex-direction: column;
						width: 100rpx;
						.food-image{
							width: 100rpx;
							height: 100rpx;
						}
						.food-describe{
							font-size: 24rpx;
							font-family: PingFangSC-Regular, PingFang SC;
							font-weight: 400;
							color: #999999;
							text-align: center;
                            white-space:nowrap;
						}
					}
					.contrast-or{
						width: 70rpx;
						.or-text{
							height: 100rpx;
							font-size: 28rpx;
							font-family: PingFangSC-Regular, PingFang SC;
							font-weight: 400;
							color: #999999;
						}
					}
				}
			}
			.content-describe{
                border-top:2rpx solid #fff;
                color: #999999;
                font-size:28rpx;
                padding:20rpx 30rpx;
			}

        
    }

    .box {
        width: 325rpx;
        height: 130rpx;
        background: #f7f9f8;
        border-radius: 10rpx;
        margin-top: 20rpx;
        .main {
            font-size: 40rpx;
            font-family: "din", DINAlternate-Bold, DINAlternate;
            font-weight: bold;
            color: #333333;
            .unit {
                font-size: 24rpx;
                font-family: PingFangSC-Medium, PingFang SC;
                font-weight: 500;
                color: #333333;
            }
        }
        .desp {
            margin-top: 10rpx;
            font-size: 24rpx;
            color: #999;
        }
    }

    .age {
        position: relative;
        .dot {
            position: absolute;
            top: 0;
            left: 0;
            width: 70rpx;
            height: 40rpx;
            background: #d9f6f4;
            border-radius: 10rpx 0px 10rpx 0px;
            font-size: 24rpx;
            color: #1dc6bd;
        }
    }
    .height {
        position: relative;
        .dot {
            position: absolute;
            top: 0;
            left: 0;
            width: 70rpx;
            height: 40rpx;
            background: #d8f3ff;
            border-radius: 10rpx 0px 10rpx 0px;
            font-size: 24rpx;
            color: #1d85c6;
        }
    }
    .weight {
        position: relative;
        .dot {
            position: absolute;
            top: 0;
            left: 0;
            width: 120rpx;
            height: 40rpx;
            background: #ffe3d9;
            border-radius: 10rpx 0px 10rpx 0px;
            font-size: 24rpx;
            color: #f9936d;
        }
    }
    .targetWeight {
        position: relative;
        .dot {
            position: absolute;
            top: 0;
            left: 0;
            width: 120rpx;
            height: 40rpx;
            background: #f1e9ff;
            border-radius: 10rpx 0px 10rpx 0px;
            font-size: 24rpx;
            color: #8864ff;
        }
    }
}
</style>
